﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Windows.Devices.Geolocation;

namespace WP8.Mapas
{
    public partial class GeolocalizacionPage : PhoneApplicationPage
    {
        public GeolocalizacionPage()
        {
            InitializeComponent();
        }

        private async void OneShotPosition_Click(object sender, RoutedEventArgs e)
        {
            Geolocator geolocator = new Geolocator();
            geolocator.DesiredAccuracyInMeters = 50;
            try
            {
                Geoposition geoposition = await geolocator.GetGeopositionAsync(maximumAge: TimeSpan.FromMinutes(5), timeout: TimeSpan.FromSeconds(10));
                LatitudeTextBlock.Text = geoposition.Coordinate.Latitude.ToString("0.00");
                LongitudeTextBlock.Text = geoposition.Coordinate.Longitude.ToString("0.00");
            }
            catch (UnauthorizedAccessException)
            {  // the app does not have the right capability or the location master switch is off  
                StatusTextBlock.Text = "location  is disabled in phone settings.";
            }
        }
    }
}